# Maintainer: Dominic Sisneros <dsisnero@gmail.com>

_realname=mruby
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.0
pkgrel=1
pkgdesc="mruby is the lightweight implementation of the Ruby language (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/mruby"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-ruby"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "bison")
source=(${_realname}-${pkgver}.zip::"https://github.com/${_realname}/${_realname}/archive/${pkgver}.zip"
        "https://github.com/mruby/mruby/commit/47092cc.patch")
sha256sums=('c7d95fdc05efdc8f5a0df4d5f0fbad5092596d61927c39515d03b8dde4743a8e'
            '096b853e4819bdd4d90e923df19ade662b1a6333d41b16fe3e63833438ca1fc3')

prepare() {
  cd  "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/47092cc.patch"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf "${srcdir}/${_realname}-${pkgver}" ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  # touch to ensure bison is regenerated, to ensure it's working
  touch mrbgems/mruby-compiler/core/parse.y

  ./minirake -v
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  install -d "${pkgdir}${MINGW_PREFIX}"/bin

  # In build_config\default.rb file, enable_debug option is disabled for performance
  # https://github.com/mruby/mruby/commit/3c55cb089514d40ff17e9f29f9195c85111e0c10
  # cp build/host-debug/bin/* "${pkgdir}${MINGW_PREFIX}"/bin/ || return 1

  cp build/host/bin/* "${pkgdir}${MINGW_PREFIX}"/bin/ || return 1

  install -d "${pkgdir}${MINGW_PREFIX}"/lib
  cp build/host/lib/*.a "${pkgdir}${MINGW_PREFIX}"/lib/

  install -d "${pkgdir}${MINGW_PREFIX}"/include
  cp -r include/* "${pkgdir}${MINGW_PREFIX}"/include/
}
